<include file="Public:header" />
<style type="text/css">
    .add_body >div >.full-height-scroll{
        border-right:1px dotted #ccc
    }
    .add_body_title{
        margin:20px 0 0 10px;
        padding-left: 14px;
    }
    .add_body_form>form>.form-group{
        margin-bottom: 25px;
    }
    body{overflow-y:hidden;}
    .product_thead>tr>td{
        background-color:#FFFFFF;padding:1px;font-size:13px;color:#999;
    }
</style>
<script>
    $(function () {
        $(".add_body").height(window.innerHeight - $("#add_body").offset().top - $("#tfoot_div").height() - 40);
        $(window).resize(function () {
            $(".add_body").height(window.innerHeight - $("#add_body").offset().top - $("#tfoot_div").height() - 40);
        })
    })
</script>
<div class="wrapper wrapper-content animated fadeIn">
    <include file="Public:alert" />
    <form class="form-horizontal" id="form" role="form" action="{:U('business/edit')}" method="post" enctype="multipart/form-data">
        <input type="hidden" name="refer_url" value="{$refer_url}" />
        <input type="hidden" name="business_id" value="{$business_info['business_id']}" />
        <div class="ibox-content add_body" id="add_body" >
            <div class="row">
                <div class="col-md-6 add_body" style="padding-right: 0px;">
                    <div class="full-height-scroll">
                        <div class="row">
                            <div class="col-md-12 add_body_title" >
                                <div class="all-inline">
                                    <span class="sq-tag"></span>
                                    <div class="text-tag">
                                        <span>基础信息</span>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-11 add_body_form" style="margin:20px 0 0 20px;">
                                <div class="form-group">
                                    <label class="col-md-4 control-label">项目编号：</label>
                                    <div class="col-md-6">
                                        <div class="input-daterange input-group" style="height:35px;">
                                            <span class="input-group-addon" style="background-color:#ccc;text-align:left;">{$business_info['code']}</span>
                                        </div>
                                    </div>
                                    <div class="col-md-2"></div>
                                </div>
                                <volist name="field_list['main']" id="vo" key="key">
                                    <if condition="$vo['field'] eq 'status_id'">
                                        <!--<div class="form-group">-->
                                        <!--<label class="col-md-4 control-label">项目状态组：</label>-->
                                        <!--<div class="col-md-6">-->
                                        <!--<select name="status_type_id" id="type_id" class="form-control">-->
                                        <!--<volist name="type_list" id="vo">-->
                                        <!--<option value="{$vo['id']}" <if condition = "$business_info['status_type_id'] eq $vo['id']">selected</if>>{$vo['name']}</option>-->
                                        <!--</volist>-->
                                        <!--</select>-->
                                        <!--</div>-->
                                        <!--<div class="col-md-2"><span style="color:red;line-height: 32px;margin-left: 10px;">*</span></div>-->
                                        <!--</div>-->
                                        <div class="form-group">
                                            <label class="col-md-4 control-label">项目进度：</label>
                                            <div class="col-md-6">
                                                <select name="status_id" id="status_id" class="form-control" >
                                                    <volist name="status_list" id="vo">
                                                        <option value="{$vo['status_id']}" <if condition = "$vo['status_id'] eq $business_info['status_id']">selected</if>>{$vo['name']}</option>
                                                    </volist>
                                                </select>
                                            </div>
                                            <div class="col-md-2"><span style="color:red;line-height: 32px;margin-left: 10px;">*</span></div>
                                        </div>
                                        <elseif condition = "$vo['field'] eq 'customer_id'" />
                                        <div class="form-group">
                                            <label class="col-md-4 control-label">客户名称：</label>
                                            <div class="col-md-6">
                                                <input type="hidden" name="customer_id" id="customer_id" value="{$business_info.customer_id}" />
                                                <input class="form-control required" aria-required="true" placeholder="请点击选择"  type="text" name="customer_name" id="customer_name" value="{$business_info.customer_name}" readonly="true" style="cursor:pointer;" title="请点击选择"/>
                                            </div>
                                            <div class="col-md-2"><span style="color:red;line-height: 32px;margin-left: 10px;">*</span></div>
                                        </div>
                                        <elseif condition = "$vo['field'] eq 'contacts_id'" />
                                        <div class="form-group">
                                            <label class="col-md-4 control-label">联系人：</label>
                                            <div class="col-md-6">
                                                <input type="hidden" name="contacts_id" id="contacts_id" value="{$business_info.contacts_id}" />
                                                <input class="form-control " aria-required="true" placeholder="请点击选择" type="text" name="contacts_name" value="{$business_info.contacts_name}" id="contacts_name" readonly="true" style="cursor:pointer;" title="请点击选择"/>
                                            </div>
                                            <div class="col-md-2"></div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-4 control-label">维护人：</label>
                                            <div class="col-md-6">
                                                <input type="hidden" name="joiner" id="user_id" value="{$business_info.joiner}" />
                                                <input class="form-control required" aria-required="true" placeholder="请点击选择"  type="text" name="joiner_name" id="user_name" value="{$business_info.joiner_name}" readonly="true" style="cursor:pointer;" title="请点击选择"/>
                                            </div>
                                            <div class="col-md-2"><span style="color:red;line-height: 32px;margin-left: 10px;">*</span></div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-md-4 control-label">项目成员：</label>
                                            <div class="col-md-6">
                                                <input type="hidden" name="parter" id="parter_id" value="{$business_info.parter}" />
                                                <input class="form-control" aria-required="true" placeholder="请点击选择"  type="text" name="parter_name" id="parter_name" value="{$business_info.parter_name}" readonly="true" style="cursor:pointer;" title="请点击选择"/>
                                            </div>
                                            <!--<div class="col-md-2"><span style="color:red;line-height: 32px;margin-left: 10px;">*</span></div>-->
                                        </div>
                                        <elseif condition = "$vo['field'] eq 'minage'" />
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">年龄要求：</label>
                                            <div class="col-md-1"></div>
                                            <div class="col-sm-4">
                                                <div class="input-group">
                                                    <input class="form-control" type="text" name="minage" value="{$business_info['minage']}"  onkeyup="num_input(this)"><span class="input-group-addon">~</span>
                                                    <input class="form-control" type="text" name="maxage" value="{$business_info['maxage']}" onkeyup="num_input(this)"><span class="input-group-addon">岁</span>
                                                </div>
                                            </div>
                                            <div class="col-md-2"></div>
                                        </div>
                                        <elseif condition = "$vo['field'] eq 'minsalary'" />
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">年薪范围：</label>
                                            <div class="col-md-1"></div>
                                            <div class="col-sm-4">
                                                <div class="input-group">
                                                    <input class="form-control" type="text" name="minsalary" value="{$business_info['minsalary']}"  onkeyup="num_input(this)"><span class="input-group-addon">~</span>
                                                    <input class="form-control" type="text" name="maxsalary" value="{$business_info['maxsalary']}"  onkeyup="num_input(this)"><span class="input-group-addon">万元</span>
                                                </div>
                                            </div>
                                            <div class="col-md-2"></div>
                                        </div>
                                        <elseif condition="$vo['field'] == 'pro_type'"/>
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">项目类型：</label>
                                            <div class="col-md-1"></div>
                                            <div class="col-sm-4">
                                                {$vo.html}
                                            </div>
                                            <div class="col-md-2"><span style="color:red;line-height: 32px;margin-left: 10px;">*</span></div>
                                        </div>
                                        <elseif condition = "$vo['field'] eq 'minexp'" />
                                        <div class="form-group">
                                            <label class="col-sm-3 control-label">工作年限要求：</label>
                                            <div class="col-md-1"></div>
                                            <div class="col-sm-4">
                                                <div class="input-group">
                                                    <input class="form-control" type="text" name="minexp" value="{$business_info['minexp']}"  onkeyup="num_input(this)"><span class="input-group-addon">~</span>
                                                    <input class="form-control" type="text" name="maxexp" value="{$business_info['maxexp']}"  onkeyup="num_input(this)"><span class="input-group-addon">年</span>
                                                </div>
                                            </div>
                                            <div class="col-md-2"></div>
                                        </div>
                                        <else />
                                        <div class="form-group">
                                            <label class="col-md-4 control-label">{$vo.name}：</label>
                                            <if condition="$vo['form_type'] == 'textarea'">
                                                <if condition = "$vo['tip_start'] eq 1">
                                                    <div class="col-md-6">
                                                        {$vo.html}
                                                    </div>
                                                    <div class="col-md-2"><span style="color: red;line-height: 32px;margin-left: 10px;">*</span></div>
                                                    <else/>
                                                    <div class="col-md-8">
                                                        {$vo.html}
                                                    </div>
                                                </if>
                                                <elseif condition="$vo['form_type'] == 'address' || $vo['form_type'] == 'box'"/>
                                                <if condition = "$vo['tip_start'] eq 1">
                                                    <div class="col-md-6">
                                                        {$vo.html}
                                                    </div>
                                                    <div class="col-md-2"><span style="color: red;line-height: 32px;margin-left: 10px;">*</span></div>
                                                    <else/>
                                                    <div class="col-md-8">
                                                        <if condition="$vo['field'] == 'grade'">
                                                            <input type="hidden" id="star" name="grade" value="{$business_info['grade']}">
                                                            <div class="all-star" style="font-size: 18px;padding-top:3px;color:#D0D0D0;">
                                                                <i class="fa fa-star">&nbsp;&nbsp;</i><i class="fa fa-star">&nbsp;&nbsp;</i><i class="fa fa-star">&nbsp;&nbsp;</i><i class="fa fa-star">&nbsp;&nbsp;</i><i class="fa fa-star">&nbsp;&nbsp;</i>
                                                            </div>
                                                            <else/>
                                                            {$vo.html}
                                                        </if>

                                                    </div>
                                                </if>
                                                <elseif condition="$vo['form_type'] == 'p_box'"/>
                                                <div class="col-md-6">
                                                    <select name="possibility" id="possibility" class="form-control">
                                                        <volist name="possibility_list" key="key1" id="vo">
                                                            <option value="{$vo}%" <if condition = "$business_info['possibility'] eq $vo.'%'">selected</if>>{$vo}%</option>
                                                        </volist>
                                                    </select>
                                                </div>
                                                <div class="col-md-2"></div>
                                                <elseif condition="$vo['field'] == 'name'"/>
                                                <div class="col-md-6">
                                                    <input class="form-control required" name="name" value="{$business_info['name']}" type="text"/>
                                                </div>
                                                <if condition = "$vo['tip_start'] eq 1">
                                                    <div class="col-md-2"><span style="color: red;line-height: 32px;margin-left: 10px;">*</span></div>
                                                    <else/>
                                                    <div class="col-md-2"></div>
                                                </if>

                                                <else/>
                                                <div class="col-md-6">
                                                    {$vo.html}
                                                </div>
                                                <if condition = "$vo['tip_start'] eq 1">
                                                    <div class="col-md-2"><span style="color: red;line-height: 32px;margin-left: 10px;">*</span></div>
                                                    <else/>
                                                    <div class="col-md-2"></div>
                                                </if>
                                            </if>
                                        </div>
                                    </if>
                                </volist>
                            </div>
                            <div class="col-md-12 add_body_title">
                                <div class="all-inline">
                                    <span class="sq-tag"></span>
                                    <div class="text-tag">
                                        <span>附加信息</span>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-11 add_body_form" style="margin:20px 0 0 20px;">
                                <volist name="field_list['data']" id="vo" key="key">
                                    <div class="form-group">
                                        <label class="col-md-4 control-label">{$vo.name}：</label>
                                        <if condition="$vo['form_type'] == 'address' || $vo['form_type'] == 'box'">
                                            <if condition = "$vo['tip_start'] eq 1">
                                                <div class="col-md-6">
                                                    {$vo.html}
                                                </div>
                                                <div class="col-md-2"><span style="color: red;line-height: 32px;margin-left: 10px;">*</span></div>
                                                <else/>
                                                <div class="col-md-8">
                                                    {$vo.html}
                                                </div>
                                            </if>
                                            <else/>
                                            <div class="col-md-6">
                                                {$vo.html}
                                            </div>
                                            <if condition = "$vo['tip_start'] eq 1">
                                                <div class="col-md-2"><span style="color: red;line-height: 32px;margin-left: 10px;">*</span></div>
                                                <else/>
                                                <div class="col-md-2"></div>
                                            </if>
                                        </if>
                                    </div>
                                </volist>
                            </div>
                            <div class="col-md-1 pull-right">
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>

        <div id="tfoot_div" class="clearfix">
            <div class="clearfix" id="tfoot_page">
                <div class="ibox-content" style="border-top: none;">
                    <div class="col-sm-offset-2">
                        <input type="hidden" name="submit" value="保存项目" />
                        <button type="submit" class="btn btn-primary">保存</button>
                        <input class="btn btn-default" type="button" onclick='javascript:location.href="{:U(index)}"' value="{:L('RETURN')}"/>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>
<div style="display:none" id="dialog-customer-list" title="{:L('SELECT_THE_CUSTOMER')}">
    <div class="spiner-example">
        <div class="sk-spinner sk-spinner-three-bounce">
            <div class="sk-bounce1"></div>
            <div class="sk-bounce2"></div>
            <div class="sk-bounce3"></div>
        </div>
    </div>
</div>
<div style="display:none" id="dialog-role-list2" title="选择维护人">
    <div class="spiner-example">
        <div class="sk-spinner sk-spinner-three-bounce">
            <div class="sk-bounce1"></div>
            <div class="sk-bounce2"></div>
            <div class="sk-bounce3"></div>
        </div>
    </div>
</div>
<div style="display:none" id="dialog-role-list3" title="选择维护人">
    <div class="spiner-example">
        <div class="sk-spinner sk-spinner-three-bounce">
            <div class="sk-bounce1"></div>
            <div class="sk-bounce2"></div>
            <div class="sk-bounce3"></div>
        </div>
    </div>
</div>
<div style="display:none" id="dialog-contacts-list" title="选择联系人">
    <div class="spiner-example">
        <div class="sk-spinner sk-spinner-three-bounce">
            <div class="sk-bounce1"></div>
            <div class="sk-bounce2"></div>
            <div class="sk-bounce3"></div>
        </div>
    </div>
</div>
<div style="display:none" id="dialog-product-list" title="添加产品">
    <div class="spiner-example">
        <div class="sk-spinner sk-spinner-three-bounce">
            <div class="sk-bounce1"></div>
            <div class="sk-bounce2"></div>
            <div class="sk-bounce3"></div>
        </div>
    </div>
</div>
<div style="display:none" id="dialog-validate" title="{:L('BUSINESS_OPPORTUNITIES_OF_TEST_RESULTS')}">
    {:L('HAS_THE_FOLLOWING_BUSINESS_OPPORTUNITIES_ARE_SIMILAR_TO_THE_BUSINESS_NAME')}
    <div id="search_content"></div>
</div>
<script type="text/javascript">
    $("[data-type='nummber']").keyup(function () {
        if (isNaN($(this).val())) {
            $(this).val($(this).val().replace(/\D/g, ''))
        }
    });

    $(document).ready(function () {
        /*form表单验证*/
        $("#form").validate({

        });
    });

    $(function () {
        $('#name').blur(function () {
            name = $('#name').val();
            if (name != '') {
                $.post('{:U("business/check")}',
                        {
                            name: name
                        },
                        function (data) {
                            if (data.data != 0) {
                                var result = '';
                                $.each(data.data, function (k, v) {
                                    result += (k + 1) + '、' + v + '</br>';
                                });
                                $('#dialog-validate').dialog('open');
                                $("#search_content").html(result);
                            }
                        },
                        'json');
            }
        });

        $('#customer_name').click(function () {
            $('#dialog-customer-list').dialog('open');
            $('#dialog-customer-list').load("{:U('Customer/listDialog')}");
        });

        $('#contacts_name').click(function () {
            var customer_id = $('#customer_id').val();
            $('#dialog-contacts-list').dialog('open');
            $('#dialog-contacts-list').load("{:U('contacts/radiolistdialog','id=')}" + customer_id);
        });

        //项目状态组
        $('#type_id').change(function () {
            var type_id = $(this).val();
            var temp = '';
            if (type_id) {
                $.ajax({
                    'type': 'get',
                    'data': {'type_id': type_id},
                    'dataType': 'json',
                    'url': '{:U("business/getbusinessStatus")}',
                    'success': function (data) {
                        if (data.status == 1) {
                            $('#status_id').html('');
                            $.each(data.data, function (k, v) {
                                temp += '<option value="' + v.status_id + '">' + v.name + '</option>';
                            });
                            $('#status_id').html(temp);
                        } else {
                            alert_crm(data.info)
                        }
                    }
                });
            }
        });
    });

    $('#dialog-customer-list').dialog({
        autoOpen: false,
        modal: true,
        width: 700,
        maxHeight: 400,
        buttons: {
            "{:L('CONFIRM')}": function () {
                var item = $('input:radio[name="customer"]:checked').val();
                var name = $('input:radio[name="customer"]:checked').parent().next().html();
                var contacts_id = $('input:radio[name="customer"]:checked').attr('rel');
                var contacts_name = $('input:radio[name="customer"]:checked').next().attr('value');
                $('#customer_name').val(name);
                $('#customer_id').val(item);
                $('#contacts_id').val(contacts_id);
                $('#contacts_name').val(contacts_name);
                $(this).dialog("close");
            },
            "{:L('CANCEL')}": function () {
                $(this).dialog("close");
            }
        },
        position: ["center", 100]
    });
    $('#dialog-contacts-list').dialog({
        autoOpen: false,
        modal: true,
        width: 700,
        maxHeight: 400,
        buttons: {
            "{:L('CONFIRM')}": function () {
                var item = $('input:radio[name="contacts"]:checked').val();
                var name = $('input:radio[name="contacts"]:checked').parent().next().html();
                var customer_id = $('input:radio[name="contacts"]:checked').next().val();
                var customer_name = $('input:radio[name="contacts"]:checked').next().attr('rel');
                $('#contacts_name').val(name);
                $('#contacts_id').val(item);
                $('#customer_id').val(customer_id);
                $('#customer_name').val(customer_name);
                $(this).dialog("close");
            },
            "{:L('CANCEL')}": function () {
                $(this).dialog("close");
            }
        },
        position: ["center", 100]
    });
    $("#dialog-validate").dialog({
        autoOpen: false,
        modal: true,
        width: 400,
        maxHeight: 400,
        buttons: {
            "{:L('CONFIRM')}": function () {
                $(this).dialog("close");
            }
        },
        position: ["center", 100]
    });
</script>
<script type="text/javascript">
    var now_rows = {$max_key};
    var total_row_id = {$max_key};
    //减少一条信息
    $(document).on('click', '.reduce_one', function () {
        var row_id = $(this).parent().parent().attr('id');
        row_val = row_id.substr(4);
        if ($('#product_id_' + row_val).val() == '') {
            $('#' + row_id).remove();
            calculate(total_row_id);
        } else {
            swal({
                title: "温馨提示",
                text: "您确定要移除该商品吗?",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "是的，我要移除！",
                cancelButtonText: '让我再考虑一下…',
                closeOnConfirm: false,
                closeOnCancel: false
            },
                    function (isConfirm) {
                        if (isConfirm) {
                            $('#' + row_id).remove();
                            calculate(total_row_id);
                            swal("移除成功！", "您已经移除了该商品信息！", "success");
                        } else {
                            // return false;
                            swal("已取消", "您取消了移除操作！", "error");
                        }
                    });
        }
        // now_rows --;
    });

    $(".addproduct").click(function () {
        $('#dialog-product-list').dialog('open');
        $('#dialog-product-list').load('{:U("product/mutildialog")}');
    });

    //商品浮动层
    $("#dialog-product-list").dialog({
        autoOpen: false,
        modal: true,
        width: 850,
        maxHeight: 500,
        position: ["center", 100],
        buttons: {
            '{:L("OK")}': function () {
                $(".se_product").each(function () {
                    now_rows += 1;
                    var product_name = $(this).text();
                    $('#view_row').remove();
                    var product_id = $(this).attr('rel');
                    var muns = 0;
                    $('.cproduct_id').each(function (k, v) {
                        if ($(v).val() == product_id) {
                            alert_crm('此产品已经存在，如需添加请直接修改数量!');
                            muns += 1;
                        }
                    });
                    if (muns == 0) {
                        var unit_price = $(this).children("input:first-child").val();
                        var category_name = $(this).children("input:first-child").next().next().next().val();
                        var standard = $(this).children("input:first-child").next().val();
                        if (product_id != null) {
                            $('#product_name_' + now_rows).val(product_name);
                            $('#add_products').append("<tr id='row_" + now_rows + "'><td style='text-align:center;'><a href='javascript:void(0);' class='reduce_one'><i class='icon-minus'></i></a></td><td><input type='hidden' name='business[product][" + now_rows + "][product_id]' id='product_id_" + now_rows + "' class='cproduct_id' value='" + product_id + "' /><input type='text' class='form-control' readonly='true' id='product_name_" + now_rows + "' style='border:none;!important' readonly='readonly' value='" + product_name + "'/></td><td><input type='text' id='product_ori_price_" + now_rows + "' name='business[product][" + now_rows + "][ori_price]' class='form-control' style='border:none;!important' readonly='readonly'  value='" + unit_price + "' /></td><td><input type='text' class='form-control product_discount_rate' name='business[product][" + now_rows + "][discount_rate]' id='product_discount_rate_" + now_rows + "' onblur='bu(this)' onkeyup='calculate(" + now_rows + ",1)' placeholder='0.00' /></td><td><input type='text' class='form-control' name='business[product][" + now_rows + "][unit_price]' id='product_unit_price_" + now_rows + "' onkeyup='calculate(" + now_rows + ")' style='' value='" + unit_price + "' /></td><td><input type='text' class='form-control amount' name='business[product][" + now_rows + "][amount]' id='product_amount_" + now_rows + "' onkeyup='calculate(" + now_rows + ")' value='1'/></td><td><input type='text' style='border:none;!important' name='business[product][" + now_rows + "][unit]' readonly='readonly' class='form-control' value='" + standard + "'/></td><td><input type='text' class='form-control subtotal' name='business[product][" + now_rows + "][subtotal]' id='product_subtotal_" + now_rows + "' style='border:none;!important' readonly='readonly' rel='" + now_rows + "'/></td></tr>");
                            calculate(now_rows);
                        }
                    }
                });
                $(this).dialog('close');
            },
            '{:L("CANCEL")}': function () {
                $(this).dialog('close');
            }
        },
        close: function () {
            $(this).html('');
        }
    });

    //根据选项计算价格
    function calculate(param, par) {
        par = par || 0;
        if ($('#product_id_' + param).val() != '' && $('#product_id_' + param).val() != '0') {
            //先对当前Row进行计算
            //先对当前Row进行计算
            var amount = $('#product_amount_' + param).val();//数量
            //过滤数量
            amount = amount.replace(/\D/g, ''); //清除"数字"和"."以外的字符
            $('#product_amount_' + param).val(amount);

            //产品单价
            var ori_price = $('#product_ori_price_' + param).val();

            //产品售价
            var unit_price = $('#product_unit_price_' + param).val();
            //过滤售价
            unit_price = unit_price.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
            unit_price = unit_price.replace(/^\./g, ""); //验证第一个字符是数字
            unit_price = unit_price.replace(/\.{2,}/g, "."); //只保留第一个, 清除多余的
            unit_price = unit_price.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
            unit_price = unit_price.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
            $('#product_unit_price_' + param).val(unit_price);

            //产品折扣
            var discount = $('#product_discount_rate_' + param).val();
            //过滤折扣
            discount = discount.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
            discount = discount.replace(/^\./g, ""); //验证第一个字符是数字
            discount = discount.replace(/\.{2,}/g, "."); //只保留第一个, 清除多余的
            discount = discount.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
            discount = discount.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
            $('#product_discount_rate_' + param).val(discount);

            if (discount != 0) {
                var discount_rate = $('#product_discount_rate_' + param).val();
            } else {
                var discount_rate = $('#discount_rate').val();
            }
            discount_rate = new Number(discount_rate);
            var product_discount = cal_discount_money(unit_price, amount);//折扣额
            var unit_val = 0.00;
            if (par == 0) {
                if (ori_price == 0 || ori_price == 0.00) {
                    discount_rate = '0.00';
                } else {
                    discount_rate = parseFloat((ori_price - unit_price) / ori_price * 100).toFixed(2);
                    if (unit_price == 0 || unit_price == 0.00) {
                        discount_rate = '100.00';
                    }
                }
                unit_val = unit_price;
                $('#product_discount_rate_' + param).val(discount_rate);
                var subtotal = parseFloat(unit_val * amount).toFixed(2); //小计
            } else {
                if (discount_rate > 0) {
                    discount_rate = parseFloat(discount_rate / 100).toFixed(2);
                    var unit_val = parseFloat(ori_price * (1 - discount_rate)).toFixed(2);
                } else {
                    var unit_val = parseFloat(ori_price).toFixed(2);
                }
                $('#product_unit_price_' + param).val(unit_val);
                var subtotal = parseFloat(unit_val * amount).toFixed(2); //小计
            }
            $('#product_subtotal_' + param).val(subtotal);
            $('#product_discount_' + param).val(product_discount);
            //合计数量
            var total_amount = 0;
            $('.amount').each(function (k, v) {
                if ($(v).val() != '' || $(v).val() != '0') {
                    total_amount += new Number($(v).val());
                }
            });
            $('#total_amount_val').html(total_amount);
            $('#total_amount').val(total_amount);

            //合计小计
            var total_subtotal = 0.00;
            $('.subtotal').each(function (k, v) {
                if ($(v).val() != '' || $(v).val() != '0') {
                    total_subtotal += new Number($(v).val());
                }
            });
            //alert(total_subtotal);
            $('#total_subtotal_val').text(total_subtotal.toFixed(2));
            $("[name='total_subtotal_val']").val(total_subtotal.toFixed(2));
            $('#total_subtotal').val(total_subtotal.toFixed(2));
            $('#business_price').val(total_subtotal.toFixed(2));
            $('#final_price').val(total_subtotal.toFixed(2));

            final_price_sum('rate');

        } else {
            return false;
        }
    }
    //根据选项计算价格 END
    /**
     *计算销售价格
     */
    function cal_discount_money(unit_price, amount, discount_rate) {
        var product_discount = 0;
        if (discount_rate == 0) {
            product_discount = 0;
        } else {
            product_discount = (unit_price * amount) * (discount_rate / 100);
        }
        return parseFloat(product_discount).toFixed(2);
    }

    /**
     *计算总订单金额
     */
    function final_price_sum(status) {
        //产品合计
        var total_subtotal_val = $('[name="total_subtotal_val"]').val();
        //整单折扣
        var final_discount_rate = $('#final_discount_rate').val();
        if (status == 'business_price') {
            //订单金额
            var final_price = $('#business_price').val();
        } else {
            //订单金额
            var final_price = $('#final_price').val();
        }

        if (status == 'rate') {
            //过滤
            final_discount_rate = final_discount_rate.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
            final_discount_rate = final_discount_rate.replace(/^\./g, ""); //验证第一个字符是数字
            final_discount_rate = final_discount_rate.replace(/\.{2,}/g, "."); //只保留第一个, 清除多余的
            final_discount_rate = final_discount_rate.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
            final_discount_rate = final_discount_rate.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
            $('#final_discount_rate').val(final_discount_rate);

            if (final_discount_rate > 100) {
                $('#final_discount_rate').val('0.00');
                $('#final_discount_rate').focus();
                final_price_sum('rate');
                alert_crm('整单折扣不能大于100');
                return false;
            }

            final_price = parseFloat(total_subtotal_val * (1 - final_discount_rate / 100)).toFixed(2);
            $('#final_price').val(final_price);
        } else {
            //过滤
            final_price = final_price.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
            final_price = final_price.replace(/^\./g, ""); //验证第一个字符是数字
            final_price = final_price.replace(/\.{2,}/g, "."); //只保留第一个, 清除多余的
            final_price = final_price.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
            final_price = final_price.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数

            //整单折扣
            if (final_price == 0 || final_price == 0.00 || total_subtotal_val == 0 || total_subtotal_val == 0.00) {
                final_discount_rate = '0.00';
            } else {
                final_discount_rate = parseFloat((total_subtotal_val - final_price) / total_subtotal_val * 100).toFixed(2);
            }

            $('#final_discount_rate').val(final_discount_rate);
        }
        $('#business_price').val(final_price);
        $('#final_price').val(final_price);
    }
</script>
<script>
    var star = $('#star').val();
    if (star == '' || star == null) {
        $('.fa-star').removeClass("star-orange");
    } else {
        $('.fa-star').removeClass("star-orange");
        $('.fa-star:lt(' + star + ')').addClass("star-orange");
    }
    /*星星特效*/
    $('.fa-star').mousemove(function () {
        $(this).addClass("star-orange");
        $(this).prevAll().addClass("star-orange");
        $(this).nextAll().removeClass("star-orange");
    });
    $('.fa-star').mouseout(function () {
        var star = $('#star').val();
        if (star == '' || star == null) {
            $('.fa-star').removeClass("star-orange");
        } else {
            $('.fa-star').removeClass("star-orange");
            $('.fa-star:lt(' + star + ')').addClass("star-orange");
        }
    });
    $('.fa-star').click(function () {
        var num = $(this).index() + 1;
        $('#star').val(num);

    });

    $('#user_name').click(function () {
        $('#dialog-role-list2').dialog('open');
        $('#dialog-role-list2').load("{:U('User/listDialog')}");
    });
    $('#dialog-role-list2').dialog({
        autoOpen: false,
        modal: true,
        width: 700,
        maxHeight: 400,
        buttons: {
            "{:L('CONFIRM')}": function () {
                var joiner = new Array();
                var joiner_name = new Array();
                $('input:checkbox[name="owner"]:checked').each(function () {
                    joiner.push($(this).val());
                    joiner_name.push($(this).attr('rel'));
                })
                joiner = joiner.join(",");
                joiner_name = joiner_name.join(",");
                var nameskey = sessionStorage.getItem("nameskey");
                var idskey = sessionStorage.getItem("idskey");
                $('#user_name').val("");
                $('#user_id').val("");
                $('#user_name').val(nameskey);
                $('#user_id').val(idskey);
//                $('#user_name').val(joiner_name);
//                $('#user_id').val(joiner);
                $(this).dialog("close");
            },
            "{:L('CANCEL')}": function () {
                $(this).dialog("close");
            }
        },
        position: ["center", 100]
    });

    $('#parter_name').click(function () {
        let temp = $('#parter_id').val();
        $('#dialog-role-list3').dialog('open');
        var str;
        if(temp){
            str = "{:U('User/mutilistdialog')}&by=all&pater="+temp;
        }
        else{
            str = "{:U('User/mutilistdialog','by=all')}";
        }
        $('#dialog-role-list3').load(str);
    });

    $('#dialog-role-list3').dialog({
        autoOpen: false,
        modal: false,
        width: 800,
        height: 400,
        close: function () {
            $(this).html("");
        },
        buttons: {
            "{:L('CONFIRM')}": function () {
                var parter = new Array();
                var parter_name = new Array();
                $(".muti_role_id:checked").each(function () {
                    parter.push($(this).val());
                    parter_name.push($(this).attr('rel'));
                })
                parter = parter.join(",");
                parter_name = parter_name.join(",");
                $('#parter_name').val("");
                $('#parter_id').val("");
                $('#parter_name').val(parter_name);
                $('#parter_id').val(parter);
                $(this).dialog("close");
            },
            "{:L('CANCEL')}": function () {
                $(this).dialog("close");
            }
        },
        position: ["center", 100]
    });
</script>
<include file="Public:footer" />
<script src="__PUBLIC__/resume_selector/common.21a64352.js"></script>
<script src="__PUBLIC__/resume_selector/resume.search.910ebde0.js "></script>